package com.pengji.rcp.plugin.date;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileRead {
	public static void main(String[] args) {
		BufferedReader br;
		BufferedWriter bw;
		try {
			br = new BufferedReader(new InputStreamReader(new FileInputStream(
					"C:\\Users\\Administrator\\Desktop\\1.txt"), "utf-8"));
			bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("1.txt")));
			String data = null;
			int i = 0, j = 0;

			String date = "";
			String mes = "";
			long l = 0L;
			while ((data = br.readLine()) != null) {
				++i;
				if (i % 6 == 0) {
					date = "";
					// System.out.println(data + "\t\t" + 6);
				}
				if (i % 6 == 1) {
					// System.out.println(data + "\t\t" + 1);
				}
				if (i % 6 == 2) {
					// System.out.println(data + "\t\t" + 2);
				}
				if (i % 6 == 3) {
					// date = data + " ";
					date = data;
					// System.out.println(data + "\t\t" + 3);
				}
				if (i % 6 == 4) {
					date += data;
					date = date.replace("/", "");
					date = date.replace(":", "");
					SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");
					Date sendDate = null;
					;
					try {
						sendDate = (Date) df.parse(date);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					l = Test.main(sendDate);
					j++;
					//System.out.println(l);
					// System.out.println(date + "\t\t 3 4");
					// System.out.println(data + "\t\t" + 4);
				}
				if (i % 6 == 5) {
					// if (data.length() > 40) {
					mes = data;
					// System.out.println(data + "\t\t" + 5);
					// }
				}
				// System.out.println(mes);
				if (i % 6 == 0) {
					System.out
							.println("<sms protocol=\"0\" address=\"13810946301\" date=\""+l+"\" type=\"1\" subject=\"null\" body=\""
									+ mes
									+ "\" toa=\"null\" sc_toa=\"null\" service_center=\"13800100500\" read=\"1\" status=\"-1\" />");
					bw.write("<sms protocol=\"0\" address=\"13810946301\" date=\""+l+"\" type=\"1\" subject=\"null\" body=\""
									+ mes
									+ "\" toa=\"null\" sc_toa=\"null\" service_center=\"13800100500\" read=\"1\" status=\"-1\" />");
					bw.newLine();

				}
			}
			bw.flush();
			bw.close();
			System.out.println(j);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
